const app = getApp();
Component({
  mixins: [],
  data: {
    value:""
  },
  props: {
    title:'',
    reserved_pop:true,
    typeData:[],
    typeData_sl:[],
    style:'',
    show:false,
    selecttitle:'',
    isImg:true,
    isearch:false,  //是否显示搜索框框
    isClick:true,   //允许弹出
    onGetItem: (data) => { },
    onClick: (data) => { }
  },
  didMount() {

  },
  didUpdate() {},
  didUnmount() {}, 
  methods: {
    select(e){
      var that = this;
      var item = e.currentTarget.dataset.item;
      that.props.onGetItem(item);
      that.close();
      
    },
    close(){
      var that = this;
      that.setData({
        show:false
      })
    },
    open(){
      var that = this;
      if(that.props.isClick){
        that.setData({
          show:true
        })
      }else{
        that.props.onClick();
      }
      
    }, 

    //搜索名称
    onInputBatchName(e){
      var that = this;
      var value = e.detail.value;
      that.setData({
        value:value
      })
        
    },

    //点击搜索
    searchList(){
      var that = this;
      var typeData_sl = that.props.typeData_sl;
      var value = that.data.value;
      that.setData({
        typeData : that.fuzzyQuery(typeData_sl,value)
      })    
    },

     // 实现模糊查询
   fuzzyQuery(list, keyWord) {
    var arr = [];
    for (var i = 0; i < list.length; i++) {
      var name = String(list[i].name);
      var code = String(list[i].code);
      if (name.indexOf(keyWord) >= 0||code.indexOf(keyWord) >= 0 ) {
        arr.push(list[i]);
      }
    }
    return arr;
  },

  }
});
